package com.builder;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import com.model.Usuario;
import com.view.ClienteView;
import com.view.UsuarioView;

@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class UsuarioBuilder extends BaseBuilder<UsuarioView, Usuario> {

	@ManagedProperty("#{clienteBuilder}")
	private ClienteBuilder clienteBuilder;

	public Usuario toDomain(UsuarioView view) {
		return new Usuario(view.getId(), view.getUsuario(),
				view.getContrsenia(), view.getEnabled().booleanValue(), null,
				view.getCliente() != null ? clienteBuilder.toDomain(view
						.getCliente()) : null);
	}

	public UsuarioView toView(Usuario model) {
		return new UsuarioView(model.getID(), model.getUsuario(),
				model.getContrasenia(), model.isEnable(),
				model.getCliente() != null ? clienteBuilder.toView(model
						.getCliente()) : new ClienteView());
	}

	public ClienteBuilder getClienteBuilder() {
		return clienteBuilder;
	}

	public void setClienteBuilder(ClienteBuilder clienteBuilder) {
		this.clienteBuilder = clienteBuilder;
	}

}
